# -*- coding: utf-8 -*-

#0,1,2->A,B,C
PillarA = 0
PillarB = 1
PillarC = 2

PillarCharMap = {0:'A',1:'B',2:'C'}

PillarCount = 3

def Hanoi(n):
    PillarStackMap = {}
    DishPosMap = {}
    PillarStackMap[PillarA] = []
    PillarStackMap[PillarB] = []
    PillarStackMap[PillarC] = []
    print("-----------------InitDataOver-----------------")
    # print("DishPosMap:",DishPosMap)
    # print("PillarStackMap:",PillarStackMap)

    stack = PillarStackMap[PillarA]
    for x in range(1,n + 1):
        stack.append(x)
        # print("stack:",stack)
        DishPosMap[x] = PillarA
    print("-----------------InitStackOver----------------")
    # print("DishPosMap:",DishPosMap)
    print("PillarStackMap:",PillarStackMap)

    Hanoi_Iter(n,n,DishPosMap,PillarStackMap)

    print("PillarStackMap:",PillarStackMap)

def Move(stackFrom,stackTo):
    dish = stackFrom.pop(0)
    stackTo.insert(0,dish)
    return dish

def GetNextPillar(pillar,direc):
    nextPillar = -1
    if direc == True:
        nextPillar = pillar + 1
        if nextPillar >= PillarCount:
            nextPillar = 0
    else:
        nextPillar = pillar - 1
        if nextPillar < 0:
            nextPillar = PillarCount - 1

    return nextPillar

def Hanoi_Iter(n,maxCount,dishPosMap,pillarStackMap):
    if(n == 0):
        return
    Hanoi_Iter(n-1,maxCount,dishPosMap,pillarStackMap)
    
    direc = (maxCount + n) % 2 != 0
    pillar = dishPosMap[n]
    nextPillar = GetNextPillar(pillar,direc)
    stackFrom = pillarStackMap[pillar]
    stackTo = pillarStackMap[nextPillar]
    Move(stackFrom,stackTo)
    dishPosMap[n] = nextPillar   
    print("# %s --> %s" % (PillarCharMap[pillar],PillarCharMap[nextPillar]))

    Hanoi_Iter(n-1,maxCount,dishPosMap,pillarStackMap)

if __name__ == '__main__':
    Hanoi(5)